package com.example.video.adapter

import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.alibaba.android.arouter.launcher.ARouter
import com.bumptech.glide.Glide
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.base.entity.CategoryEntityItem
import com.example.base.entity.Child
import com.example.video.R

class TwoAdapter:BaseQuickAdapter<CategoryEntityItem,BaseViewHolder>(R.layout.item_two) {
    override fun convert(holder: BaseViewHolder, item: CategoryEntityItem) {
        holder.setText(R.id.two_name,item.name)
        val rv = holder.getView<RecyclerView>(R.id.two_rv)
        //需要适配器
        val twoChildAdapter = TwoChildAdapter()
        twoChildAdapter.data.addAll(item.child)
        rv.adapter = twoChildAdapter
        rv.layoutManager = GridLayoutManager(context,3)
    }
}

class TwoChildAdapter:BaseQuickAdapter<Child,BaseViewHolder>(R.layout.item_two_child){
    override fun convert(holder: BaseViewHolder, item: Child) {
        Glide.with(context).load(item.extra).into(holder.getView(R.id.two_iv))
        holder.setText(R.id.two_tv,item.name)
        holder.itemView.setOnClickListener {
            ARouter.getInstance().build("/app/CateXqActivity").withInt("cid",item.id).withString("cname",item.name).navigation()
        }
    }
}